#encoding=utf-8
import sys
sys.path.append("../")
import jieba
import string
import jieba.posseg as pseg
def filter_str(instr):
    deEstr = string.punctuation + ' ' + string.digits + string.letters
    deCstr = '，。《》【】（）！？★”“、：…'
    destr = deEstr + deCstr
    outstr = ''
    for char in instr.decode('utf-8'):
        if char not in destr.decode('utf-8'):
            outstr += char
    return outstr
def get_words_rate(instr):
    b = filter_str(instr)
    words=pseg.cut(b)
    wordtable={}
    f = open('E:\Python27\Swords.txt','r')
    filelines = f.readlines()
    SWstr = ''
    for x in filelines:
        if x[-1] == '\n':
            x = x[0:-1]
            SWstr = SWstr + x
    f.close()
    for w in words:
        if w.word not in SWstr.decode('GBK'):
            wordtable[w.word] = wordtable.get(w.word,0) + 1
        else:
            pass
    return wordtable
#s = "我一贯认为，我们必须首先从客户体验出发，继而再回头考虑技术上的可行性。不能一味钻研技术然后再考虑可以把它用到什么产品上，以及用什么办法把它卖掉。我犯过这个错误可能比在场的任何人都要多。伤痕历历在目。"
#test = get_words_rate(s)
